USE BMIG_Mensual_POST_CADENA
go

IF OBJECT_ID('dbo.WASP_M0016_Calcula_Cuotas') IS NOT NULL 
   BEGIN
      DROP PROCEDURE dbo.WASP_M0016_Calcula_Cuotas 
      IF OBJECT_ID('dbo.WASP_M0016_Calcula_Cuotas') 
      IS
      NOT NULL 
         PRINT 
         '<<< FAILED DROPPING PROCEDURE dbo.WASP_M0016_Calcula_Cuotas >>>' 
      ELSE
         PRINT '<<< DROPPED PROCEDURE dbo.WASP_M0016_Calcula_Cuotas >>>' 
   END
go

SET ANSI_NULLS ON
go

SET QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE WASP_M0016_Calcula_Cuotas
AS
   BEGIN
      SELECT ppsuc,
         ppcta,
         ppoper,
         COUNT(ppoper) AS cuotas 
      INTO dbo.as_cuotas_temp 
      FROM 	fsd601 (nolock) 
      WHERE 	Ppsbop = 0 
      AND ppoper <> 999999999 
      AND d601co = 'S' 
      GROUP BY 	ppsuc, ppcta, ppoper 
   END
go



SET ANSI_NULLS OFF
go

SET QUOTED_IDENTIFIER OFF
go

IF OBJECT_ID('dbo.WASP_M0016_Calcula_Cuotas') IS NOT NULL 
   PRINT '<<< CREATED PROCEDURE dbo.WASP_M0016_Calcula_Cuotas >>>' 
ELSE
   PRINT '<<< FAILED CREATING PROCEDURE dbo.WASP_M0016_Calcula_Cuotas >>>'
go
